from csagent.core.node.base_node import BaseNode
from csagent.core.context import AgentState
import time
class Node(BaseNode):
    def initialize(self):
        """初始化节点"""
        print(self.conf)
        print(f"{self.node_config.name} Node初始化成功")
    def _parse_doc(self, url):
        time.sleep(1)
        markdown = '章节内容1\n章节内容2\n章节内容3\n章节内容4\n章节内容5\n章节内容6\n章节内容7\n章节内容8'
        return markdown
    def execute(self, state: AgentState, stream_writer=None) -> AgentState:
        print(f"{self.node_config.name} node开始执行")
        doc_url = state['params']['url']
        markdown = self._parse_doc(doc_url)
        print(f"markdown:{markdown}")
        trunk_list = markdown.split('\n')
        for index, item in enumerate(trunk_list):
            # 需要存在特定的parallel_info字段中，kv格式
            state['parallel_info'][str(index)] = {'doc_trunk':item}
        print(f"{self.node_config.name} node执行完成")
        return state